<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCarOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('car_orders', function (Blueprint $table) {
            $table->id();
            $table->string('source')->nullable()->comment('订单来源');
            $table->string('phone')->nullable()->comment('手机号');
            $table->string('wx_name')->nullable()->comment('微信名称');
            $table->string('position')->nullable()->comment('取车经纬度');
            $table->string('return_position')->nullable()->comment('还车经纬度');
            $table->longText('drink')->nullable()->comment('随车饮料');
            //车系
            $table->decimal('lease_price')->default(0.00)->comment('原车辆日租金');
            $table->decimal('last_lease_price')->default(0.00)->comment('修改后的日租金');
            $table->timestamp('pre_fetch_time')->nullable()->comment('租车起始时间');
            $table->timestamp('pre_return_time')->nullable()->comment('租车终止时间');
            $table->unsignedInteger('rate')->default(0)->comment('折扣');
            $table->decimal('lease_total_price')->default(0.00)->comment('租金总价');
            $table->string('deposit',)->nullable()->comment('押金');
            $table->string('break_rules',)->nullable()->comment('违章押金');
            $table->decimal('total',10,2)->default(0.00)->comment('预付总金额');
            $table->integer('car_id')->default(0)->comment('车辆id');
            $table->integer('last_car_id')->default(0)->comment('真实排车车辆id');
            $table->string('name')->nullable()->comment('车辆名称');
            $table->string('last_name')->nullable()->comment('真实排车车辆名称');
            $table->string('openid')->default(0)->comment('用户openid');
            $table->string('order_sn')->nullable()->unique()->comment('订单编号');
            $table->string('transaction_id')->nullable()->comment('微信订单编号');
            $table->string('out_refund_no')->nullable()->comment('退款订单编号');
            $table->string('order_category')->nullable()->comment('订单分类');
            $table->string('nick_name')->nullable()->comment('昵称');
            $table->string('avatar')->nullable()->comment('头像');
            $table->string('customer_name')->nullable()->comment('顾客名称');
            $table->unsignedInteger('car_category')->default(0)->comment('车系分类');
            $table->integer('days')->default(0)->comment('租车天数');
            $table->dateTime('pay_time')->nullable()->comment('下单时间');
            $table->decimal('base_price',10,2)->default(0.00)->comment('基础价格');
            $table->decimal('service_price',10,2)->default(0.00)->comment('保障费');
            $table->decimal('brokerage',10,2)->default(0.00)->comment('整备费');
            $table->timestamp('send_car_time')->nullable()->comment('排车时间');
            $table->integer('pre_lease_days')->default(0)->comment('预租车时长');
            $table->timestamp('fetch_time')->nullable()->comment('实际取车时间');
            $table->timestamp('return_time')->nullable()->comment('实际还车时间');
            $table->integer('lease_days')->default(0)->comment('实际租车时长');
            $table->decimal('fact_lease_price')->default(0.00)->comment('实际租车价格');
            $table->tinyInteger('status')->default(0)
                ->comment('订单状态 -1:客户取消订单,1:已经下单未付款,2:已下单未发货,3:已下单已发货,4:已下单已经完成发货,5:商家取消订单,6:订单完成,7:订单超时');
            $table->tinyInteger('pay_type')->default('1')->comment('支付类型默认1小程序2支付宝3刷卡');
            $table->string('out_trade_no')->nullable()->comment('自定义商户号');
            $table->string('license')->nullable()->comment('车牌');
            $table->string('return_address')->nullable()->comment('还车地址');
            $table->string('fetch_address')->nullable()->comment('取车地址');
            $table->string('city')->nullable()->comment('城市');
            $table->tinyInteger('is_coupon')->default(0)->comment('是否启用优惠券');
            $table->integer('coupon_id')->default(0)->comment('优惠券id');
            $table->decimal('coupon_price')->default(0.00)->comment('优惠券面额');
            $table->integer('pre_hours')->default(0)->comment('小时');
            $table->integer('fetch_hours')->default(0)->comment('实际小时');
            $table->string('send_mileage')->nullable()->comment('送车公里数');
            $table->string('get_mileage')->nullable()->comment('取车公里数');
            $table->text('sundry_fee')->nullable()->comment('其它费用');
            $table->tinyInteger('process_status')->default(1)->comment('员工送车状态默认1送车2还车3统计4统计结束');
            $table->unsignedInteger('send_employer_id')->default(0)->comment('送车人id');
            $table->string('send_employer_nickname')->nullable()->comment('送车人');
            $table->string('send_employer_phone')->nullable()->comment('送车人电话');
            $table->string('return_employer_nickname')->nullable()->comment('还车人');
            $table->string('return_employer_phone')->nullable()->comment('还车人电话');
            $table->unsignedInteger('return_employer_id')->default(0)->comment('还车人id');
            $table->string('send_car_order_no')->nullable()->comment('送车单号');
            $table->string('operator')->nullable()->comment('客户经理');
            $table->unsignedInteger('operator_id')->default(0)->comment('客户经理id');
            $table->text('outset_photo')->nullable()->comment('出发照片');
            $table->text('return_photo')->nullable()->comment('还回照片');
            $table->string('return_mileage')->nullable()->comment('还车公里数');
            $table->timestamp('fact_send_at')->nullable()->comment('实际送车时间');
            $table->timestamp('dispatch_at')->nullable()->comment('派单时间');
            $table->timestamp('verify_at')->nullable()->comment('验车时间');
            $table->timestamp('catch_at')->nullable()->comment('抢单时间');
            $table->timestamp('pay_for_at')->nullable()->comment('付款时间');

            $table->string('service')->nullable()->comment('精选服务');
            $table->decimal('service_price',10,2)->default(0.00)->comment('精选服务');
            $table->longText('fact_service_list')->nullable()->comment('所有服务列表');
            $table->decimal('fact_service_total',10,2)->default(0.00)->comment('实际精选服务');


            $table->decimal('pre_base_price_total',10,2)->default(0.00)->comment('优惠前基本保障费');
            $table->decimal('pre_brokerage_total',10,2)->default(0.00)->comment('优惠前车辆整备费');
            $table->decimal('pre_lease_price_total',10,2)->default(0.00)->comment('优惠前租金');
            $table->decimal('pre_total',10,2)->default(0.00)->comment('优惠前共计');
            $table->decimal('pre_service_total',10,2)->default(0.00)->comment('优惠前精选服务');

            $table->decimal('bc_base_price_total',10,2)->default(0.00)->comment('优惠后基本保障费');
            $table->decimal('bc_brokerage_total',10,2)->default(0.00)->comment('优惠后车辆整备费');
            $table->decimal('bc_lease_price_total',10,2)->default(0.00)->comment('优惠后租金');
            $table->decimal('bc_total',10,2)->default(0.00)->comment('优惠后共计');
            $table->decimal('bc_service_total',10,2)->default(0.00)->comment('优惠后精选服务');
            $table->decimal('order_part_refund_total',10,2)->default(0.00)->comment('累计退款金额');
            $table->longText('send_car_photo')->nullable()->comment('送车照');



            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('car_orders');
    }
}
